package vn.vnu.uet.university;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import vn.vnu.uet.university.bean.DatabaseHandler;
import vn.vnu.uet.university.bean.ThongBao;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class Report extends DefaultActivity{
	ListView listContent;
	List<ThongBao> thongBaoList = new ArrayList<ThongBao>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState, R.layout.report);
		
		this.setTitle("Thông báo");
		
		DatabaseHandler db = new DatabaseHandler(Report.this);
		
		listContent = (ListView) findViewById(R.id.listContent);

		ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> map = new HashMap<String, String>();
		
		thongBaoList = db.getAllThongBao();
		
		for(int i = 0; i < thongBaoList.size(); i++) {
			map = new HashMap<String, String>();
			map.put("item_icon", String.valueOf(R.drawable.card_default));
			map.put("item_text", thongBaoList.get(i).getTitle());
			listItem.add(map);
		}

		SimpleAdapter mSchedule = new SimpleAdapter(Report.this, listItem,
				R.layout.row_item, new String[] { "item_icon", "item_text" },
				new int[] { R.id.item_icon, R.id.item_text });
		listContent.setAdapter(mSchedule);
		
		listContent.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
				Intent intent = new Intent(Report.this, ViewContent.class);
				intent.putExtra("position", thongBaoList.get(position).getId());
				intent.putExtra("class", 2);
				startActivity(intent);
			}
		});
	}

}
